home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2009 December / maximum-cd-2009-12.iso / DiscContents / gimp-2.7.0-i686-setup.exe / {app} / share / gimp / 2.0 / scripts / script-fu-set-cmap.scm < prev    next >
Encoding:
GIMP Script-Fu Script  |  2009-08-19  |  2.2 KB  |  65 lines

  1. ; Set Colormap v1.1  September 29, 2004
  2. ; by Kevin Cozens <kcozens@interlog.com>
  3. ;
  4. ; Change the colourmap of an image to the colours in a specified palette.
  5. ; Included is script-fu-make-cmap-array (available for use in scripts) which
  6. ; returns an INT8ARRAY containing the colours from a specified palette.
  7. ; This array can be used as the cmap argument for gimp-image-set-cmap.
  8.  
  9. ; GIMP - The GNU Image Manipulation Program
  10. ; Copyright (C) 1995 Spencer Kimball and Peter Mattis
  11. ;
  12. ; This program is free software: you can redistribute it and/or modify
  13. ; it under the terms of the GNU General Public License as published by
  14. ; the Free Software Foundation; either version 3 of the License, or
  15. ; (at your option) any later version.
  16. ;
  17. ; This program is distributed in the hope that it will be useful,
  18. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20. ; GNU General Public License for more details.
  21. ;
  22. ; You should have received a copy of the GNU General Public License
  23. ; along with this program.  If not, see <http://www.gnu.org/licenses/>.
  24.  
  25. (define (script-fu-make-cmap-array palette)
  26.   (let* (
  27.         (num-colours (car (gimp-palette-get-info palette)))
  28.         (cmap (cons-array (* num-colours 3) 'byte))
  29.         (colour 0)
  30.         (i 0)
  31.         )
  32.  
  33.     (while (< i num-colours)
  34.       (set! colour (car (gimp-palette-entry-get-color palette i)))
  35.       (aset cmap (* i 3) (car colour))
  36.       (aset cmap (+ (* i 3) 1) (cadr colour))
  37.       (aset cmap (+ (* i 3) 2) (caddr colour))
  38.       (set! i (+ i 1))
  39.     )
  40.  
  41.     cmap
  42.   )
  43. )
  44.  
  45. (define (script-fu-set-cmap img drawable palette)
  46.   (gimp-image-set-colormap img
  47.                            (* (car (gimp-palette-get-info palette)) 3)
  48.                            (script-fu-make-cmap-array palette))
  49.   (gimp-displays-flush)
  50. )
  51.  
  52. (script-fu-register "script-fu-set-cmap"
  53.     _"Se_t Colormap..."
  54.     _"Change the colormap of an image to the colors in a specified palette."
  55.     "Kevin Cozens <kcozens@interlog.com>"
  56.     "Kevin Cozens"
  57.     "September 29, 2004"
  58.     "INDEXED*"
  59.     SF-IMAGE     "Image"    0
  60.     SF-DRAWABLE  "Drawable" 0
  61.     SF-PALETTE  _"Palette"  "Default"
  62. )
  63.  
  64. (script-fu-menu-register "script-fu-set-cmap" "<Image>/Colors/Map/Colormap")
  65.